/*
 * @Description:
 * @Author: qingyang
 * @Date: 2023-02-27 09:50:22
 * @LastEditors: qingyang
 * @LastEditTime: 2023-03-07 16:21:53
 */
import { reactive, markRaw } from 'vue';
import { CPageTableProps, ColumnSettingTypeEnum, SearchOptionsType } from '@/components/CPageTable';
import { useRoute } from 'vue-router';
import { CarbonInventoryStandardsEnum, CarbonInventoryStandardsOption } from '@/constants/enum';
export const useInventory = () => {
  const route = useRoute();
  // 搜索字段及其他
  const searchForm = reactive({
    type: 'EmissionSummary',
    standard: 'ISO' as keyof typeof CarbonInventoryStandardsEnum
  });

  // 搜索配置
  const searchOptions: SearchOptionsType[] = markRaw([
    {
      name: '标准',
      field: 'standard',
      type: 'headerTab',
      headerTabList: CarbonInventoryStandardsOption
    },
    {
      name: '标准',
      field: 'type',
      type: 'filterTab',
      filterTabList: [
        {
          label: '排放汇总表',
          value: 'EmissionSummary'
        },
        {
          label: '排放源识别表',
          value: 'SourceIdentification'
        },
        {
          label: '活动数据收集表',
          value: 'DataCollection'
        },
        {
          label: '排放因子选择表',
          value: 'FactorSelection'
        },
        {
          label: '排放量计算表',
          value: 'EmissionCalculation'
        }
      ]
    }
  ]);

  const tableFieldsSetting: CPageTableProps['tableFieldsSetting'] = [
    {
      title: '监测计划名称',
      field: 'inventoryName',
      slot: 'inventoryNameSlot',
      minWidth: '250',
      columnSettingConfig: {
        enabled: true
      }
    },
    {
      title: '组织名称',
      field: 'organizationName',
      minWidth: '150',
      columnSettingConfig: {
        enabled: true
      }
    },
    {
      title: '适用年份',
      field: 'applicableYear',
      width: '85',
      columnSettingConfig: {
        enabled: true
      }
    },
    {
      title: '创建人/创建时间',
      field: 'creator',
      slot: 'creatorSlot',
      width: '160',
      columnSettingConfig: {
        enabled: true
      }
    },
    {
      title: '更新时间',
      field: 'updateTime',
      width: '180',
      columnSettingConfig: {
        enabled: true
      }
    },
    {
      title: '发布时间',
      field: 'releaseTime',
      width: '180',
      columnSettingConfig: {
        enabled: true
      }
    },
    {
      key: 'status',
      title: '发布状态',
      field: 'status',
      slot: 'statusSlot',
      fixed: 'right',
      width: '120',
      columnSettingConfig: {
        enabled: true
      }
    },
    {
      key: 'op',
      title: '操作',
      field: 'op',
      slot: 'opSlot',
      minWidth: '220',
      fixed: 'right',
      columnSettingConfig: {
        enabled: true,
        type: ColumnSettingTypeEnum.FIXED
      }
    }
  ];

  const options = reactive<CPageTableProps>({
    title: route.query.title as string,
    searchOptions,
    // tableOptions,
    // tableFieldsSetting,
    enableFieldsSetting: true,
    isSingleFilterTab: true,
    isShowRefreshBtn: false,
    isShowSettingBtn: false
  });
  return {
    // 头部右侧筛选项配置
    searchOptions,
    // 筛选项字段
    searchForm,
    // 配置
    options
  };
};
